package cxydmmszl.chapter08.t129;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * <li style="color: red;">Prob</li>
 * 奇数下标都是奇数或者偶数下标都是偶数
 * <li style="color: red;">Desc</li>
 *
 * <li style="color: red;">Link</li> CD24
 *
 * @author habitplus
 * @since 2021-09-06 15:55
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bf.readLine());
        int[] arr = new int[n];
        String[] ss = bf.readLine().split(" ");

        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(ss[i]);
        }
        bf.close();


        modify(arr);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(arr[i]).append(" ");
        }
        System.out.println(sb.toString());
    }

    public static void modify(int[] arr) {
        if(arr == null || arr.length < 2) {
            return;
        }

        int n = arr.length;
        int odd = 1, even = 0, end = n - 1;

        while (even < n && odd < n) {
            if ((arr[n - 1] & 1) == 0) {
                // 偶数
                swap(arr, n - 1, even);
                even += 2;
            } else {
                // 奇数
                swap(arr, n - 1, odd);
                odd += 2;
            }
        }
    }

    private static void swap(int[] arr, int i, int j) {
        if (i == j) return ;
        int t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
}
